/*
* 云记录
*/

'use strict'

YX.fn.createTeamImfo = function () {
	// this.$cloudMsg = $('#cloudMsg')
    this.$createTeamContainer = $('#createTeamContainer')
 	// this.$cloudMsg.on('click', this.showCloudMsg.bind(this, this.$cloudMsg));
    this.$createTeamContainer.delegate('.j-backBtn', 'click', this.closeCreateTeamContainer.bind(this));
    this.$createTeamContainer.delegate('.createbtnConfirm',"click",this.createSaveTeamImfo.bind(this));
    this.$createTeamContainer.delegate('.createbtnCancle',"click",this.createCancleTeamImfo.bind(this));
    // this.$cloudMsgContainer.delegate('.j-loadMore', 'click', this.loadMoreCloudMsg.bind(this))
    // this.$cloudMsgContainer.delegate('.j-mbox','click',this.playAudio)
    this.createCaseId = "";
    this.tempCreditorName = ""
}
/**
 * 创建群组
 */
YX.fn.showCreateTeamInfo = function (caseId,creditorName) {
    var that = this
    this.createCaseId = caseId;
    this.tempCreditorName = creditorName;
    this.$createTeamContainer.load('./create_team.html', function() {
        that.$createTeamContainer.removeClass('hide')
        //设置默认值
        $('#createTeamName').val(that.tempCreditorName+"与赢火虫交流群")
        // var id = that.crtSessionAccount,
        //     scene = that.crtSessionType,
        //     param ={
        //         scene:scene,
        //         to:id,
        //         lastMsgId:0,
        //         limit:20,
        //         reverse:false,
        //         done:that.cbCloudMsg.bind(that)
        //     }
        // that.mysdk.getHistoryMsgs(param)

        // /** 通话中的设置 */
		// var tmp = that.myNetcall;
		// tmp.$goNetcall.toggleClass("hide", !tmp.netcallActive);
    })
}

// 返回按钮 
YX.fn.closeCreateTeamContainer = function () {
    this.$createTeamContainer.addClass('hide');
    //再次打开案件详情页面
    this.showCaseInfo("",this.createCaseId)
}

//完成按钮
YX.fn.createSaveTeamImfo = function(){
    var $inputName = $('#createTeamName'),
        $inputItr = $('#createTeamIntr'),
        name = $inputName.val().trim(),
        itr = $inputItr.val().trim(),
		that = this,
		teamId = this.crtSessionAccount
	if (name.length > 0) {
		//开始调用赢火虫内部服务的接口
		var bodyInfo = {//1902201511010030
			"caseId": this.createCaseId,
            "intro": itr,
            "joinmode": 0,
            "magree": 0,
            "msg": "赢火虫邀请您加入本群",
            "tname": name
          }
        //   console.log("创建群提交消息====",bodyInfo)
		  firefly_IM_request.getRequest("post","/netease-im/im/team",bodyInfo,function(data){
			  if(data.isSuccess == "T"){
                that.cache.addTeam(JSON.parse(data.body))
                that.buildTeams()
                $('#teamsWrap .j-advanceTeam li[data-account="' + JSON.parse(data.body).teamId + '"]').click()
			  }else{
				// console.log("_that===",_that)
			  }
		  },function(data){
	  
		  });
	} else {
		
	}
}

//取消创建
YX.fn.createCancleTeamImfo = function(){
    // this.$createTeamContainer.addClass('hide')
    var that = this;
    window.minAlert.alert({
        type: 'warnning',
        title:"确定要取消创建么?",
        msg:"取消后您填写的内容将不保存哦",
        cancelBtnMsg: '取消', //取消按钮的按钮内容
        confirmBtnMsg:'确定', //确定按钮的按钮内容
        showConfirm:true,
        cbConfirm: function(){
            that.$createTeamContainer.addClass('hide')
        }
      });
}

